using Firestarter.DB.Schema.BO;
using Firestarter.DM_DB.Logic;
using FireStarterModeller.BO;
using FireStarterModeller.Test;
using Habanero.Base;
using NUnit.Framework;

namespace Firestarter.DB_DM.Logic.Test
{
    [TestFixture]
    public class TestDBFactory_CreateDBColumn : TestBase
    {
        [Test]
        public void Test_CreateDBColumn_DatabaseFieldName()
        {
            //---------------Set up test pack-------------------
            IPropDef boProp = TestUtilsDMProperty.CreateUnsavedValidDMProperty();
            DBFactory factory = TestDBFactory.CreateDBFactory();
            //---------------Execute Test ----------------------
            DBColumn dbColumn = factory.CreateDBColumn(boProp);
            //---------------Test Result -----------------------
            Assert.AreEqual(boProp.DatabaseFieldName, dbColumn.ColumnName);
        }

       [Test]
       public void Test_CreateDBColumn_Description()
       {
           //---------------Set up test pack-------------------
           IPropDef boProp = TestUtilsDMProperty.CreateUnsavedValidDMProperty();
           DBFactory factory = TestDBFactory.CreateDBFactory();
           //---------------Execute Test ----------------------
           DBColumn dbColumn = factory.CreateDBColumn(boProp);
           //---------------Test Result -----------------------
           Assert.AreEqual(boProp.Description, dbColumn.Comment);
       }

       [Test]
       public void Test_CreateDBColumn_Nullable_False()
       {
           //---------------Set up test pack-------------------
           IPropDef boProp = TestUtilsDMProperty.CreateUnsavedValidDMProperty();
           boProp.Compulsory = true;
           DBFactory factory = TestDBFactory.CreateDBFactory();
           //---------------Execute Test ----------------------
           DBColumn dbColumn = factory.CreateDBColumn(boProp);
           //---------------Test Result -----------------------
           Assert.IsFalse(dbColumn.Nullable.Value);
       }

       [Test]
       public void Test_CreateDBColumn_Nullable_True()
       {
           //---------------Set up test pack-------------------
           IPropDef boProp = TestUtilsDMProperty.CreateUnsavedValidDMProperty();
           boProp.Compulsory = false;
           DBFactory factory = TestDBFactory.CreateDBFactory();
           //---------------Execute Test ----------------------
           DBColumn dbColumn = factory.CreateDBColumn(boProp);
           //---------------Test Result -----------------------
           Assert.IsTrue(dbColumn.Nullable.Value);
       }

       [Test]
       public void Test_CreateDBColumn_AutoIncrementing_False()
       {
           //---------------Set up test pack-------------------
           IPropDef boProp = TestUtilsDMProperty.CreateUnsavedValidDMProperty();
           boProp.AutoIncrementing = false;
           DBFactory factory = TestDBFactory.CreateDBFactory();
           //---------------Execute Test ----------------------
           DBColumn dbColumn = factory.CreateDBColumn(boProp);
           //---------------Test Result -----------------------
           Assert.IsFalse(dbColumn.IsAutoIncrementing.Value);
       }

       [Test]
       public void Test_CreateDBColumn_AutoIncrementing_True()
       {
           //---------------Set up test pack-------------------
           IPropDef boProp = TestUtilsDMProperty.CreateUnsavedValidDMProperty();
           boProp.AutoIncrementing = true;
           DBFactory factory = TestDBFactory.CreateDBFactory();
           //---------------Execute Test ----------------------
           DBColumn dbColumn = factory.CreateDBColumn(boProp);
           //---------------Test Result -----------------------
           Assert.IsTrue(dbColumn.IsAutoIncrementing.Value);
       }

       [Test]
       public void Test_CreateDBColumn_UsesTypeMapperToSetDataType()
       {
           //---------------Set up test pack-------------------
           DMProperty boProp = TestUtilsDMProperty.CreateUnsavedValidDMProperty();
           DMPropertyType propertyType = new DMPropertyType("System", "String");
           boProp.PropertyType = propertyType;
           IDMTypeToDBColumnTypeMapper typeMapper = new DMTypeToDBColumnTypeMapper();
           DBFactory factory = new DBFactory(typeMapper);
           //---------------Assert Precondition---------------
           //---------------Execute Test ----------------------
           DBColumn dbColumn = factory.CreateDBColumn(boProp);
           //---------------Test Result -----------------------
           Assert.AreSame("VARCHAR", dbColumn.DataType);
       }
    }
}